package handler

import (
	"context"
	"gitee.com/Hu-Lyndon/distill-resk/infra/register/micro/proto"
	"net/http"
)

type User struct {
}

// 处理用户请求
func (u *User) Signup(ctx context.Context, req *proto.ReqSignup, resp *proto.RespSignup) error {
	username := req.Username
	passwd := req.Password

	// 参数简单校验
	if len(username) < 3 || len(passwd) < 5 {
		resp.Code = http.StatusBadRequest
		resp.Message = "注册参数无效"
		return nil
	}

	// 对密码进行加盐
	//encPasswd := util.Sha1([]byte(passwd + cfg.PasswordSalt))
	// 将用户信息注册到用户表中
	//suc := dblayer.UserSignup(username, encPassword)
	suc := true
	if suc {
		resp.Code = http.StatusOK
		resp.Message = "注册成功"
	} else {
		resp.Code = http.StatusBadRequest
		resp.Message = "注册失败"
	}

	return nil
}
